home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: MegaDisc
/
MegaDisc 07 (1988)(MegaDisc Digital Publishing)(AU)[WB].zip
/
MegaDisc 07 (1988)(MegaDisc Digital Publishing)(AU)[WB].adf
/
BASIC_TUTE
/
Basic_Tute
< prev
next >
Wrap
Text File
|
2000-04-10
|
11KB
|
282 lines
AMIGABASIC TUTORIAL PARTS 1-3
By Jonathan Potter
[ED NOTE: This is the first installment in a series of Basic tutorials
by Jonathan.]
INTRODUCTION
This is a tutorial for AmigaBASIC, probably the best BASIC available
for any computer. While AmigaBASIC has its disadvantages, its wide range
of commands, which give control over most of the Amiga's functions, and
BASIC's traditional simplicity, as far as programming goes, heavily
outweigh them. Commodore, however have provided their customers with a
totally inadequate manual. This tutorial does not try to replace a manual,
but I hope it will clarify a few points, especially for beginners to
programming.
STARTING IT UP
Probably the easiest way to start up AmigaBASIC is from the WorkBench,
however this is not the most efficient. WorkBench takes about 100K of
memory, memory which many serious BASIC programs will need. For using
AmigaBASIC, I have created an auto-booting disk which contains AmigaBASIC,
the DEVICES and LIBRARIES necessary to utilise the parallel and serial
ports, and the speech, and a directory for the actual programs. When the
disk is created, there is about 45% free for BASIC files.
***********************************************************************
These instructions assume you have used the CLI before, BUT IF YOU
HAVEN'T, DON'T WORRY. Just type every thing as shown, and all should be
well. They also assume you have only one drive.
***********************************************************************
Insert your WorkBench disk at the prompt (the picture), and when the
screen changes from white to whatever background colour you use, break into
the CLI with a few CTRL-Ds. [ie, keep your CTRL and D keys pressed down as
Workbench is booting up.]
The first thing to do is to create a RAMDISK containing a few, vital
commands.
MAKEDIR RAM:C
COPY C/COPY RAM:C
ASSIGN C: RAM:C
COPY C/CD RAM:C
COPY C/MAKEDIR RAM:C
COPY C/DELETE RAM:C
COPY C/FORMAT RAM:C
COPY C/INSTALL RAM:C
COPY C/LIST RAM:C
COPY C/INFO RAM:C
Remove your WorkBench disk, and insert a blank disk, with the write
protect tab towards the bottom of the disk [ie, Write-enabled, you can't
see through the tab hole]. Then type:
FORMAT DRIVE DF0: NAME AmigaBASIC
INSTALL DF0:
CD DF0:
MAKEDIR DEVS
MAKEDIR LIBS
MAKEDIR L
MAKEDIR PROGS
Remove this disk, and insert WorkBench (referred to as WB from here on).
Type:
MAKEDIR RAM:DEVS
COPY DF0:DEVS RAM:DEVS ALL
Reinsert your new AmigaBASIC disk (referred to as AB from here on).
Type:
COPY RAM:DEVS DF0:DEVS ALL
DELETE RAM:DEVS ALL
Insert WB, and type:
MAKEDIR RAM:LIBS
COPY DF0:LIBS RAM:LIBS ALL
Insert AB, and type:
COPY RAM:LIBS DF0:DEVS ALL
DELETE RAM:LIBS ALL
Insert WB, and type:
MAKEDIR RAM:L
COPY DF0:L RAM:L ALL
Insert AB, and type:
COPY RAM:L DF0:L ALL
DELETE RAM:L ALL
Then insert the Extras disk (1.2 is better), and type:
COPY DF0:AMIGABASIC RAM:
Insert AB, and type:
COPY RAM:AMIGABASIC DF0:
DELETE RAM:AMIGABASIC
You can then type LIST, and you should see something like this:
DEVS
LIBS
L
PROGS
AMIGABASIC
Type INFO to see how much room is free on your NEW AUTOBOOTING AmigaBASIC
disk!
If you only ever use one type of printer, you can type:
CD DEVS/PRINTERS
LIST
and DELETE the printers you do not want. Be sure to type in the names
exactly as shown. e.g DELETE CBM_MPS1000
You can then do a CTRL-A-A to reset, and you should see a CLI screen come
up, with the 1> prompt. Type in AMIGABASIC and press RETURN, and after a
while the AmigaBASIC screen should come up. You can then program to your
heart's content (see the next section for some ideas on how to do that!),
and when you save a program you should type SAVE "PROGS/progname". This will
save the program to the PROGS directory, and will keep your disk nice and
tidy. If you plan to be doing a lot of saving and loading, you could type
CHDIR "PROGS" and then you can omit the PROGS/ prefix to the file name.
THE `BASICS' OF PROGRAMMING
Programming in BASIC on the Amiga is as simple as on any other machine,
the only difference being the commands, and the editor you type into.
The editor (LIST Window) defaults as half a screen wide, and the full
screen high. For my purposes that size suits me fine, but you may want to
change it to cover the full screen. When AmigaBASIC first loads up, the
editor window is the current window - to make the output window the current
one, just click in it, and vice versa. While you can't move around in the
output window (with the cursor keys at least) you can in the editor, and
certain key combinations do different things.
The CURSOR KEYS by themselves will move the cursor one space in that
direction. Holding down the SHIFT with a cursor key will move one page in
that direction, and holding down ALT will move to the top or bottom of the
program (up and down cursor keys), or to the start or end of the current
line (left and right cursor keys).
Editing is simple too... you can Cut, Paste and Copy sections of the
program, with the only limit to size being the amount of memory. To mark
an area you hold down the left hand button on a particular line, and while
holding it down, move the mouse up or down, depending on which direction
you want to go. When the area has been marked, release the button, and you
can then CUT (delete) the area with Left AMIGA-X, COPY the area with Left
AMIGA-C, or PASTE a copied area with Left AMIGA-P. Note that to paste you
do not have to mark an area - the lines will be inserted from the current
cursor position downwards.
WHAT'S THIS ALL ABOUT?
I said before that this was not to replace the manual (manual? what
manual!) All it is is a simple tutorial on some of the finer points of
AmigaBASIC. So I'm not going to go on and show you how to print hello, ask
for your name, etc.. I'll assume you have used BASIC before, and just talk
about some of the better features.
So let's start with everyone's favorite...
GRAPHICS
AmigaBASIC supports all of the semi-standard BASIC graphics commands,
such as CIRCLE, LINE, PAINT, PSET, as well as a few of its own.
SCREEN and WINDOW
These can be classified as graphics commands, because they are
reasonably essential for graphics in BASIC.
SCREEN is used to define the parameters of a new screen - the width,
height, depth (number of colours) and mode are all defined by SCREEN.
The FORMAT is SCREEN screen-id, width, height, depth, mode
The SCREEN-ID is a number from 1 to 4. Screen -1 is the WorkBench
screen.
WIDTH is the width of the screen, in pixels, and can be any value
from 1 to 640. WorkBench screen width is 640.
HEIGHT is the height of the screen, in pixels, and can be any value
from 1 to 400. WorkBench screen height is 200.
DEPTH is the number of colours the screen can support. It is given
as a number which is a power of 2. Therefore, a depth of 1 allows 2 colours
(2^1), a depth of 5 allows 32 (2^5). The default WorkBench screen depth is
2 (4 colours).
MODE specifies which type of screen is to be used.
MODE SCREEN PRODUCED
1 Low Resolution (320X200), non interlaced.
2 High Resolution (640X200), non interlaced.
3 Low Resolution (320X400), interlaced.
4 High Resolution (640X400), interlaced.
WorkBench default is mode 2.
Examples.
SCREEN 1,640,200,2,2 - this will produce a WorkBench type screen.
SCREEN 3,640,400,5,4 - the highest resolution, most number of colours
possible in BASIC.
SCREEN 2,320,200,1,1 - the lowest resolution, least number of colours
possible in BASIC.
A new screen takes about 30K for a lo-res screen (320X200 mode 1), 40K
for a med-res screen (640X200 mode 2) and about 55K for a high-res screen
(640X400 mode 4). This memory is taken from the Stack (more about that
later).
AMIGABASIC TUTORIAL PART 3
WINDOW is used to define the parameters of a new window.
It has one obligatory parameter and 4 optional, in the form:
WINDOW <window-id>,[<title>],[<(x1,y1)-(x2,y2)>],[<type>],
[<screen-id>]
The WINDOW-ID is a number greater than 0. The BASIC work screen is
1. This is the obligatory parameter.
The TITLE is the window title.
(x1,y1)-(x2,y2) are the co-ordinates of the top left and bottom
right corners of the window. The default is for a full screen.
TYPE is a value from 0 to 31. The following table gives
the values and their function. To combine two or more functions,
simply add their values.
VALUE FUNCTION
1 Gives the window a sizing gadget, enabling its
size to be changed.
2 Enables the window to be moved around by the
title (drag) bar.
4 Gives the window depth gadgets, enabling it to be
moved behind and infront of other windows.
8 Gives the window a close gadget, enabling it to
be closed.
16 Makes the contents of the window reappear after
it has been covered by another window. This
takes memory from the stack.
SCREEN-ID is the screen which the window is to appear in.
The default is -1, the WorkBench screen.
Examples:
WINDOW 2,"Hi There!",(0,0)-(100,100),31,1
WINDOW 18,,,16
WINDOW 1,"HELLO!",,31
WINDOW 3,,,0
In the above examples, the first command creates a window 100X100
pixels, with all the gadgets visible, on screen 1. The second
creates a full screen window, on the WorkBench screen. The third
replaces the BASIC work window, and the fourth creates a borderless
window, on the default WorkBench screen (-1).
Note that if you wish to leave some parameters out, but include
following parameters, you must put a comma in place of the missing
parameters (e.g WINDOW 3,,(0,0)-(200,100),,2), but no commas are
necessary if no parameters follow the missing ones. This is true for
all AmigaBASIC commands.
^^^^^^^^^^^^^^^^^^^^^^^^ END OF BASIC_TUTE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^ SEE NEXT ISSUE OF MEGADISC FOR MORE ^^^^^^^^^^^^^^^^^^^